﻿@{
	ViewBag.Title = Resources.InvoiceInfoManage + ConstValues.strDash + Resources.HuiTongCIS;
}
<div id="menuBar" style="height:35px">
	<div style="float: left; padding: 5px 5px; font-weight: bold; text-align: left;">
		@Resources.InvoiceTitle/@Resources.TaxNum：<input id="selTaxNum" class="easyui-textbox" style="height:27px; width:200px;" />&nbsp;&nbsp;
		<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" onclick="searchData();">@Resources.Search</a>&nbsp;&nbsp;
		@if ((User as ICISPrincipal).IsSSA || Utility.HasSystemRole((User as ICISPrincipal), ConstValues.FunctionId.SysInvoiceMaster, RoleType.添加))
		{
			<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-add" onclick="addData();" plain="true">@Resources.Create</a>
			<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-download" onclick="downloadImportTemplate();" plain="true">@Resources.TemplateDownLoad</a>
			<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-import" onclick="openImport();" plain="true">@Resources.Import</a>
		}
		<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-export" onclick="exportData();" plain="true">@Resources.Export</a>
	</div>
	<form id="frmExport" method="post" target="iframeDownload" action="@Url.Action(nameof(SysInvoiceController.Export))">
		@Html.AntiForgeryToken()
		<input type="hidden" id="hdnIds" name="AllId" />
	</form>
	<iframe id="iframeDownload" style="width:0; height:0; visibility:hidden" tabindex="-1"></iframe>
	<div class="clear"></div>
</div>
<div id="dataGrid"></div>

@section bodyParts {
<div id="detailWindow" class="easyui-window"
	title="@Resources.InvoiceInfoManage" data-options="closed:true,minimizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="detailWindowTitle" class="tit01"></h3>
			<form id="frmDetail" method="post" enctype="multipart/form-data">
				@Html.AntiForgeryToken()
				<table width="100%" height="100%" id="tblDetail" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.InvoiceTitle：</td>
						<td style="text-align: left;" class="w2 c2">
							<input type="hidden" id="hidID" name="Id" />
							<input id="txtInvoiceTitle" name="InvoiceTitle" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true,validType:['length[1,100]']">
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.TaxNum：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtTaxNum" name="TaxNum" class="easyui-textbox" style="height:27px; width:300px;" data-options="validType:['length[1,100]']">
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.AddressAndTel：</td>
						<td style="text-align: left;" class="w2 c4" colspan="3">
							<input id="txtAddressAndTel" name="AddressAndTel" class="easyui-textbox" style="height:27px; width:892px;" data-options="validType:['length[1,200]']" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Bank：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtBank" name="Bank" class="easyui-textbox" style="height:27px; width:300px;" data-options="validType:['length[1,100]']">
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.BankAccount：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtBankAccount" name="BankAccount" class="easyui-textbox" style="height:27px; width:300px;" data-options="validType:['length[1,100]']">
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.Status：</td>
						<td style="text-align: left;" class="w2 c4">
							<select id="ddlStatus" name="status" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
								<option value="@ConstValues.Status.正常">@Resources.Normal</option>
								<option value="@ConstValues.Status.暂停">@Resources.Pause</option>
							</select>
						</td>
						<td style="text-align: right;" class="w1 c3">@Resources.Sort：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="txtSort" name="sort" class="easyui-numberbox" style="height:27px; width:300px;" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Remark：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input id="txtRemark" name="remark" class="easyui-textbox" style="height:50px; width:892px;" data-options="multiline:true,validType:['length[1,1000]']" />
						</td>
					</tr>
				</table>
			</form>
			<div class="btnDiv">
				<input type="hidden" id="hdnWindowType" />
				<input type="button" class="gbtn" onclick="saveData();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#detailWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
<div id="importWindow" class="easyui-window"
     title="@Resources.Import @Resources.InvoiceInfo" data-options="closed:true,minimizable:false,iconCls:'icon-save'"
     style="width:600px; display:none;">
	<div class="popupDiv">
		<form id="frmImport" method="post" enctype="multipart/form-data">
			@Html.AntiForgeryToken()
			<input id="importFile" name="ImportFile" class="easyui-filebox" style="height:27px; width:500px;" data-options="required:true, prompt:'@Resources.Import', buttonText:'@Resources.ChooseFile', accept:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'" />
		</form>
		<div class="buttonDiv">
			<input type="button" class="btn lbtn" onclick="importData();" value="@Resources.Import" />&nbsp;&nbsp;
			<input type="button" class="btn rbtn" onclick="$('#importWindow').window('close');" value="@Resources.Cancel" />
		</div>
	</div>
</div>
}

@section Scripts {
<script>
	common.setCurrentMenu("SysInvoice");

	$(function () {
		$("#selTaxNum").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});

		$("#dataGrid").datagrid({
			url: "@Url.Action(nameof(SysInvoiceController.GetData),
					nameof(SysInvoiceController).GetControllerName())",
			method: "get",
			fitColumns: true,
			width: $(window).width() - 285,
			height: $(window).height() - 120,
			nowrap: false,
			pagination: true,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			toolbar: "#toolBar",
			pageSize: 100,
			pageList: [100, 200, 300, 400, 500],
			columns: [[
				{ field: "id", hidden: true },
				{ field: "chk", align: "center", checkbox: true },
				@if ((User as ICISPrincipal).IsSSA ||
					Utility.HasSystemRole((User as ICISPrincipal), ConstValues.FunctionId.SysInvoiceMaster, RoleType.修改) ||
					Utility.HasSystemRole((User as ICISPrincipal), ConstValues.FunctionId.SysInvoiceMaster, RoleType.删除))
				{
					<text>
					{
						field: "operate", title: "@Resources.Operate", align: "center", width: 150,
						formatter: function(value, rec) {
							var strInfo = "";
							var tmp = rec.invoiceTitle == null ? "" : rec.invoiceTitle.replace(new RegExp("'",'g'),"’").replace(new RegExp('"','g'),"“");
							@if ((User as ICISPrincipal).IsSSA || Utility.HasSystemRole((User as ICISPrincipal), ConstValues.FunctionId.SysInvoiceMaster, RoleType.修改))
							{
								<text>
								strInfo += "<a href='#' style='color:#66CDAA;font-weight:bold;text-decoration:underline;' onclick='editData(\""
									+ rec.id + "\")'>@Resources.Modify</a>";
								</text>
							}
							@if ((User as ICISPrincipal).IsSSA || Utility.HasSystemRole((User as ICISPrincipal), ConstValues.FunctionId.SysInvoiceMaster, RoleType.删除))
							{
								<text>
								if (strInfo != "") {
									strInfo += "&nbsp;|&nbsp;";
								}
								strInfo += "<a href='#' style='color:#DC143C;font-weight:bold;text-decoration:underline;' onclick='deleteData(\""
									+ rec.id + "\",\"" + tmp + "\")'>@Resources.Delete</a>";
								</text>
							}
							return strInfo;
						}
					},
					</text>
				}
				{ field: "invoiceTitle", title: "@Resources.InvoiceTitle", align: "center", sortable: true, width: 300 },
				{ field: "taxNum", title: "@Resources.TaxNum", align: "center", sortable: true, width: 200 },
				{ field: "addressAndTel", title: "@Resources.AddressAndTel", align: "center", sortable: true, width: 300 },
				{ field: "bank", title: "@Resources.Bank", align: "center", sortable: true, width: 250 },
				{ field: "bankAccount", title: "@Resources.BankAccount", align: "center", sortable: true, width: 200 },
				{ field: "creator", title: "@Resources.Creator", align: "center", sortable: true, width: 100 },
				{ field: "createIP", title: "@Resources.CreateIP", align: "center", sortable: true, width: 150 },
				{ field: "createDate", title: "@Resources.CreateDate", align: "center", sortable: true, width: 150 },
			]],
			onBeforeLoad: function(param) {
				param.random = Math.random();
			},
			onLoadSuccess: function(data) {
				var exportIdList = $("#hdnIds").val();
				if (data.rows.length > 0) {
					var exportIdArray = exportIdList.split(',');
					for (var rowIndex = 0; rowIndex < data.rows.length; rowIndex++) {
						for (var index = 0; index < exportIdArray.length; index++) {
							if (data.rows[rowIndex].id == exportIdArray[index]) {
								$("input[type='checkbox']").eq(rowIndex + 1).prop("checked", true);
								break;
							}
						}
					}
				}
			},
			onCheck: function (rowIndex, rowData) {
				var exportIdList = $("#hdnIds").val();
				var strId = rowData.id.toString();
				if (exportIdList == "") {
					$("#hdnIds").val(strId);
				} else {
					var exportIdArray = exportIdList.split(',');
					var newArray = exportIdArray.concat(strId);
					$("#hdnIds").val(newArray.join());
				}
			},
			onUncheck: function (rowIndex, rowData) {
				var exportIdList = $("#hdnIds").val();
				var exportIdArray = exportIdList.split(',');
				var strId = rowData.id.toString();
				exportIdArray.remove(strId);
				$("#hdnIds").val(exportIdArray.join());
			},
			onCheckAll: function (rows) {
				var exportIdList = $("#hdnIds").val();
				if (exportIdList == "") {
					var newArray = new Array();
					for (var index = 0; index < rows.length; index++) {
						var strId = rows[index].id.toString();
						newArray = newArray.concat(strId);
					}
					$("#hdnIds").val(newArray.join());
				} else {
					var exportIdArray = exportIdList.split(',');
					var newArray = exportIdArray;
					for (var index = 0; index < rows.length; index++) {
						var strId = rows[index].id.toString();
						if (newArray.indexOf(strId) < 0) {
							newArray = newArray.concat(strId);
						}
					}
					$("#hdnIds").val(newArray.join());
				}
			},
			onUncheckAll: function (rows) {
				var exportIdList = $("#hdnIds").val();
				var exportIdArray = exportIdList.split(',');
				for (var index = 0; index < rows.length; index++) {
					var strId = rows[index].id.toString();
					exportIdArray.remove(strId);
				}
				$("#hdnIds").val(exportIdArray.join());
			},
		});

		$(window).resize(function () {
			$("#dataGrid").datagrid("resize", {
				width: $(window).width() - 285,
				height: $(window).height() - 110
			});
		});

		$("#detailWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});

		$("#importWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});
	});

	function searchData() {
		$("#dataGrid").datagrid("load", {
			SelTaxNum: $("#selTaxNum").textbox("getValue")
		});
	}

	function deleteData(id, name) {
		var confirmMessage = "@Resources.CfmDelete";
		confirmMessage = confirmMessage.replace(/\{0\}/g, name);
		$.messager.confirm("@Resources.Delete", confirmMessage, function (r) {
			if (r) {
				$("#hidID").val(id);
				$.post("@Url.Action(nameof(SysInvoiceController.Delete),
						nameof(SysInvoiceController).GetControllerName())",
					$("#frmDetail").serialize(),
					function(data, textStatus, jqXHR) {
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							$("#dataGrid").datagrid("reload");
						}
					}
				);
			}
		});
	};

	function addData() {
		$("#hdnWindowType").val("add");
		$("#detailWindowTitle").text("@Resources.Create");
		$("#hidID").val("");
		$("#txtInvoiceTitle").textbox("setValue","");
		$("#txtTaxNum").textbox("setValue","");
		$("#txtAddressAndTel").textbox("setValue","");
		$("#txtBank").textbox("setValue","");
		$("#txtBankAccount").textbox("setValue","");
		$("#ddlStatus").combobox("setValue", "@ConstValues.Status.正常");
		$("#txtSort").numberbox("setValue", @ConstValues.DefaultSort);
		$("#txtRemark").textbox("setValue","");
		$("#detailWindow").window("open");
	}

	function editData(id) {
		var url = "@Url.Action(nameof(SysInvoiceController.GetEditData),
				nameof(SysInvoiceController).GetControllerName())" + "/" + id;
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
				$("#dataGrid").datagrid("reload");
			} else {
				$("#hdnWindowType").val("edit");
				$("#detailWindowTitle").text("@Resources.Modify");
				$("#hidID").val(id);
				$("#txtInvoiceTitle").textbox("setValue", data.data.invoiceTitle);
				$("#txtTaxNum").textbox("setValue", data.data.taxNum);
				$("#txtAddressAndTel").textbox("setValue", data.data.addressAndTel);
				$("#txtBank").textbox("setValue", data.data.bank);
				$("#txtBankAccount").textbox("setValue", data.data.bankAccount);
				$("#ddlStatus").combobox("setValue", data.data.status);
				$("#txtSort").numberbox("setValue", data.data.sort);
				$("#txtRemark").textbox("setValue", data.data.remark);
				$("#detailWindow").window("open");
			}
		});
	}

	function saveData() {
		var isValid = $("#frmDetail").form("validate");

		if (isValid) {
			$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
				if (r) {
					var loading = layer.load(0,  {
						shade: [0.4,"#fff"]
					});
					switch ($("#hdnWindowType").val())
					{
						case "add":
							$.post("@Url.Action(nameof(SysInvoiceController.Create),
									nameof(SysInvoiceController).GetControllerName())",
								$("#frmDetail").serialize(),
								function(data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
										common.showError(data.message);
									} else {
										common.showSuccess(data.message, true);
										$("#detailWindow").window("close");
										$("#dataGrid").datagrid("reload");
									}
								}
							);
							break;
						case "edit":
							$.post("@Url.Action(nameof(SysInvoiceController.Modify),
									nameof(SysInvoiceController).GetControllerName())",
								$("#frmDetail").serialize(),
								function(data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
										common.showError(data.message);
									} else {
										common.showSuccess(data.message, true);
										$("#detailWindow").window("close");
										$("#dataGrid").datagrid("reload");
									}
								}
							);
							break;
					}
				}
			})
		}
	};

	function exportData() {
		var exportIdList = $("#hdnIds").val();
		if (exportIdList == "") {
			$.messager.alert("@Resources.Export", "@Resources.MsgRecordMust", "warning");
			return;
		}
		$("#frmExport").submit();
	}

	function downloadImportTemplate() {
		var url = "@Url.Action(nameof(SysInvoiceController.DownloadImportTemplate),
				nameof(SysInvoiceController).GetControllerName())";
		$("#iframeDownload").attr("src", url);
	}

	function openImport() {
		$("#importWindow").window("open");
	}

	function importData() {
		var loading = layer.load(0,  {
			shade: [0.4,"#fff"]
		});

		$("#frmImport").form({
			iframe: false,
			success: function (data) { }
		});

		$("#frmImport").form("submit", {
			url: "@Url.Action(nameof(SysInvoiceController.Import), nameof(SysInvoiceController).GetControllerName())",
			onSubmit: function (param) {
				param.random = Math.random();
			},
			success: function (data) {
				layer.close(loading);
				data = JSON.parse(data);
				if (data.result == "@ConstValues.AjaxFailResult") {
					common.showError(data.message);
					$("#dataGrid").datagrid("reload");
				} else {
					common.showSuccess(data.message, true);
					$("#importWindow").window("close");
					$("#dataGrid").datagrid("reload");
				}
			}
		});
	}
</script>
}